var DefaultNotifyItemRender = new Class({
	"Extends":js.underas.core.Component
	,"initialize":function(p_obj){	
		/*
		 * item padrao
		 * title
		 * subtitle
		 * count
		 * type
		 * varmod
		 * actmod		 
		 * titlemod
		 * iconmod
		 * */
		var htmlTmp = '<a href="#" data-varmod="'+p_obj.varmod+'" data-actmod="'+p_obj.actmod+'" data-titlemod="'+p_obj.titlemod+'" data-iconmod="'+p_obj.iconmod+'"><strong>'+p_obj.title+'</strong></a><span class="badge pull-right alert-'+p_obj.type+'">'+p_obj.count+'</span><br><span class="text-'+p_obj.type+'">'+p_obj.subtitle+'</span>';		
		this.parent('div',htmlTmp);
		this.getEle().addClass("divnotificao");
	}
});




js.underas.controller.Notify = new Class({
	"_item":null
	,"_itemRender":"DefaultNotifyItemRender"
	,"initialize":function(p_item){
		this._item = p_item;
	}
	,"getItemRender":function(){    	
		return this._itemRender;
	}	
	,"setItemRender":function(p_item_render){    	
		this._itemRender = p_item_render;
	}
	,"setItem":function(p_item){    	
		this._item = p_item;
	}
	,"getItem":function(p_item){    	
		return this._item;
	}
});

js.underas.controller.Notify["TP_SUCCESS"]="success";
js.underas.controller.Notify["TP_INFO"]="info";
js.underas.controller.Notify["TP_PRIMARY"]="primary";
js.underas.controller.Notify["TP_WARNING"]="warning";
js.underas.controller.Notify["TP_ERROR"]="danger";

js.underas.controller.NotifyPool = new Class({
	"Extends":js.underas.core.Component
	,"_vlcount":0
	,"initialize":function(p_title){
		//this._vlcount = p_vl_init;
		this.parent('div','<span class="glyphicon glyphicon-bell badge alert-success pull-right"><span class="notifycount">'+this._vlcount+'</span></span>'); 
		this.getEle(".glyphicon").appendHTML('<div style="z-index:9999;top:20px; left:-210px; display: none;" id="popover_'+this.uid+'" class="popover bottom in" role="tooltip"><div style="left: 90%;" class="arrow"></div><h3 class="popover-title">'+p_title+'</h3><div class="popover-content"></div></div>');
		this.getEle().addClass("column NotifyPool col-xs-2 col-sm-1 pull-right").setStyles({"z-index":"9999"});
		this.getEle("span.glyphicon").addEvent("click",this.showNotifications.bind(this));
		
		this.getEle("div.popover-content").addEvent('click:relay(.divnotificao a)',this.executeActionNotify);
	}
	,"executeActionNotify":function(evt,tgt){		
		var _linkM = this;			
		var nextload = false;
		var moduleToLoad = _linkM.get("data-varmod").toLowerCase(); 			
		if(!_linkM.hasClass("loading_module")){				
			_linkM.addClass("loading_module");
			nextload = true;
		}else if(window[moduleToLoad]){
			nextload = true;
		}			
		if(nextload){
			js.underas.core.Underas.loadModule({"mod":_linkM.get("data-varmod"),"act":_linkM.get("data-actmod"),"icon":_linkM.get("data-iconmod"),"title":_linkM.get("data-titlemod")});
		}	       
	}
	,"showNotifications":function(evt){ 
		//var cords_tmp = this.getCoordinates(); 
		//var left_tmp = parseInt(cords_tmp["left"]);
		//console.log(this.get("id").replace(ValidationType.ONLY_TEXT,"","")); 
		var pop_tmp = $$("#popover_"+this.uid); 
		var display_tmp = pop_tmp.getStyle("display")[0];
		var _display_tmp = display_tmp;
		if(display_tmp=="block"){
				display_tmp = "none";
		}	
		if(this._vlcount > 0 && _display_tmp!="block"){
				display_tmp = "block";		
		}		
		pop_tmp.setStyles({"display":display_tmp});
	}	
	,"addNotify":function(p_notify){   
		if(p_notify.getItem()){
			this._vlcount++;
			this.setValue(this._vlcount);
			$$("#popover_"+this.uid+" div.popover-content").grab(new window[p_notify.getItemRender()](p_notify.getItem()).getEle()); 
		}	
	}
	,"setValue":function(p_vl){
		this._vlcount = parseInt(p_vl);
		this.getEle(".notifycount").set("text",p_vl);
	}
	,"getValue":function(){    	
		return this._vlcount;
	}
	,"setType":function(ptype){
		var classes = this.getEle(".glyphicon").get("class");
		var ns = classes.replace(/alert\-([^\s]*)/,"alert-"+ptype);
		this.getEle(".glyphicon").set('class',ns);
	}
	,"setIcon":function(p_icon){
		var classes = this.getEle(".glyphicon").get("class");
		var ns = classes.replace(/glyphicon\-([^\s]*)/,"glyphicon-"+p_icon);
		this.getEle(".glyphicon").set('class',ns);
	}
});

js.underas.controller.NotifyPool["TP_SUCCESS"]="success";
js.underas.controller.NotifyPool["TP_INFO"]="info";
js.underas.controller.NotifyPool["TP_PRIMARY"]="primary";
js.underas.controller.NotifyPool["TP_WARNING"]="warning";
js.underas.controller.NotifyPool["TP_ERROR"]="danger";
js.underas.controller.NotifyPool["TP_DEFAULT"]="default";	

